package com.shijie.controller.app;

import com.shijie.component.AppUserService;
import com.shijie.core.Result;
import com.shijie.core.ResultGenerator;
import com.shijie.core.ServiceException;
import com.shijie.domain.entity.ShoppingTrolley;
import com.shijie.domain.entity.Skus;
import com.shijie.domain.entity.UserOrders;
import com.shijie.service.ShoppingTrolleyService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/*
 *  购物车对应的接口
 *  @author: smart boy
 *  @date: 2018-08-16
 */
@RestController
@RequestMapping("/app/shoppingTrolley")
public class ShoppingTrolleyController {

    @Resource
    private ShoppingTrolleyService shoppingTrolleyService;

    @Resource
    private AppUserService appUserService;

    /**
     * 根据SKUID获取到对应的信息
     *
     * @param skuIds skuIdA,skuIdB,skuIdC 逗号隔开
     * @return
     */
    @GetMapping
    public Result list(@RequestParam String skuIds) {
        String[] skus = skuIds.split(",");
        List<Skus> list = shoppingTrolleyService.listByIds(skus);
        return ResultGenerator.success(list);
    }

    /**
     * 购物车数据放在本地缓存，暂不需要这些数据
     *
     */
  /*  @PostMapping
    public Result save(@RequestBody ShoppingTrolley shoppingTrolley) {
        shoppingTrolley.setUserId(appUserService.getCurrentUser().getId());
        try {
            shoppingTrolleyService.save(shoppingTrolley);
        } catch (ServiceException e) {

        } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.error("加入购物车失败！");
        }
        return ResultGenerator.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        shoppingTrolleyService.deleteById(id);
        return ResultGenerator.success();
    }
    */
}

